#include "widget.h"
#include "ui_widget.h"
#include <QTableWidgetItem>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->tableWidget->insertRow(0);
    ui->tableWidget->insertRow(1);
    ui->tableWidget->insertRow(2);

    ui->tableWidget->insertColumn(0);
    ui->tableWidget->insertColumn(1);
    ui->tableWidget->insertColumn(2);

    ui->tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("学号"));
    ui->tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("姓名"));
    ui->tableWidget->setHorizontalHeaderItem(2,new QTableWidgetItem("年龄"));


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_addRow_clicked()
{
    ui->tableWidget->insertRow(ui->tableWidget->rowCount());
}

void Widget::on_pushButton_addCol_clicked()
{
    QString txt = ui->lineEdit->text();
    int column = ui->tableWidget->columnCount();
    ui->tableWidget->insertColumn(column);

    ui->tableWidget->setHorizontalHeaderItem(column,new QTableWidgetItem(txt));
}

void Widget::on_pushButton_delRow_clicked()
{
    ui->tableWidget->removeRow(ui->tableWidget->currentRow());
}


void Widget::on_pushButton_delCol_clicked()
{
    ui->tableWidget->removeColumn(ui->tableWidget->currentColumn());
}
